package com.wochao.web.admin.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wochao.model.entity.SystemPost;
import com.wochao.model.entity.SystemUser;
import com.wochao.web.admin.mapper.SystemPostMapper;
import com.wochao.web.admin.mapper.SystemUserMapper;
import com.wochao.web.admin.service.SystemUserService;
import com.wochao.web.admin.vo.system.user.SystemUserItemVo;
import com.wochao.web.admin.vo.system.user.SystemUserQueryVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemUser>
        implements SystemUserService {

    @Autowired
    private SystemUserMapper systemUserMapper;
    @Autowired
    private SystemPostMapper systemPostMapper;

    /**
     * 根据条件分页查询后台用户列表
     *
     * @param page
     * @param queryVo
     * @return
     */
    @Override
    public IPage<SystemUserItemVo> pageQuerySystemUser(IPage<SystemUserItemVo> page, SystemUserQueryVo queryVo) {
        return systemUserMapper.pageQuerySystemUser(page, queryVo);
    }

    /**
     * 根据ID查询后台用户信息
     *
     * @param id
     * @return
     */
    @Override
    public SystemUserItemVo getSystemUserById(Long id) {

        //查询后台用户信息
        SystemUser systemUser = systemUserMapper.selectById(id);
        //查询该后台用户的岗位信息
        SystemPost systemPost = systemPostMapper.selectById(systemUser.getPostId());
        //合并
        SystemUserItemVo systemUserItemVo = new SystemUserItemVo();
        BeanUtils.copyProperties(systemUser, systemUserItemVo);
        systemUserItemVo.setPostName(systemPost.getName());

        return systemUserItemVo;
    }


}




